<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>精选板块轮动</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">						
			#towriter{
				margin-top:-15px;
				border: 1px solid #555555;						
			}			
			.fixedBox{					
				white-space: nowrap;
			}
			.fixedBox::-webkit-scrollbar {
				width: 12px;     
				height: 12px;				
			}			
			p {margin-top:0px;margin-bottom:5px}				
			
			table{
				width:80px; 
				border-collapse:collapse; 
				text-align:center;
			}
			td,th{border:1px solid #696969}
			th { 
				color:#E5E5E5;  <!-- 表头文字颜色 -->
			}
			td a:link{
				color:#E5E5E5;  <!-- 列表文字颜色 -->
			}	
			
			#box {
				position: absolute;
				top: 100px;
				left: 200px;
				width: 500px;
				height: 200px;
				display: none;				
			}
			
			#bar {
				padding-top: 1px;
				height: 25px;								
				background-color: #666;
				cursor: move;
			}
			#content {				
				height: 200px;
				background-color: #000;  <!-- 弹出框背景色 -->
				white-space: nowrap;
				overflow:auto;				
			}
			#content::-webkit-scrollbar {
				width: 10px;     
				height: 10px;
				scrollbar-arrow-color:white;
				background-color: #E5E5E5;		
			}
			#content::-webkit-scrollbar-thumb {
				border-radius: 5px;
				-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
				background: rgba(0,0,0,0.2);
				scrollbar-arrow-color:#555;
			}
			#content::-webkit-scrollbar-track {
				-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
				border-radius: 0;
				background: rgba(0,0,0,0.1);
			}				
		</style>
	</head>
	<body>		
		<div id="towriter" class="fixedBox">
			<div id="title" style="margin:10px 50px -5px 5px;"></div>			
			<div id="towrites"></div>	
			<div id="box" style="background:#000;">
				<div id="bar"></div>
				<div id="content" ></div>
			</div>	
		</div>
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script> 
		<script>
			var x = 15; //显示数量
			var zx = 0; //正序 = 1; 反序 = 0;
			if(localStorage.getItem('bkldrq') != null) { //增加数量 重建日期缓存
				var t = localStorage.getItem('bkldrq');				
				if(x > t.split(';').length - 1){										
					localStorage.removeItem('bkldrq'); 					
				}	
			}
			
			var bkcolor = $("body").css("backgroundColor");
			var thcolor = "";
			var tdcolor = "";
			var cbkcolor = $("#content").css("backgroundColor");		
			var day = new Date();
			var dt = "";  //当日
			var tt = "";
			var tt1 = "";
			var k = 0;			
			window.onload = function() {
				dt = day.Format("yyyy-MM-dd");			
				changeStyle();	
				getSource();					
										
			}
			
			
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					day = new Date();
					getSource();
					if(sx == 1){
						showInform(ztgp);					
					}	
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
					if(k == 0){				
						time_range("9:00","15:15")	
					}				
				},
				60000);
			})
			
			function changeStyle() {
				var obj = document.getElementById("towriter");								
				obj.style.left= "0px"; 				
				obj.style.width= "100%";	
				obj.style.height= "320px";
				obj.style.border= "none";
				
				var div = document.getElementById("towrites");
				div.style.left= "0px"; 				
				div.style.width= x * 200 + "px";	 //根据屏幕宽窄微调；
				div.style.height= "100%";
				
				
				for (i = 1; i < x + 1; i++){
					var obj = document.createElement("div");
					if(zx == 0){					
						obj.id = "towrite" + i;
					}else if(zx == 1){
						obj.id = "towrite" + (x + 1 - i);
					}
					obj.className = "fixedBox";
					obj.style.position= "relative"; 
					obj.style.float= "left"; 
					obj.style.left= "0px"; 	
					//obj.style.marginLeft= "-5px"; 
					obj.style.width= "180px";     //板块列表宽度
					obj.style.height= "90%";					
					obj.style.fontSize="12px";	
					//obj.style.border= "1px solid #696969";
					div.appendChild(obj);					
				}				
			}					
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};			
			
			function NumberTransform(num) { 
				var result = parseFloat(num);
				if (isNaN(result)) {                    
                   return false;  
               }  				
               if(Math.abs(result) > 100000000){
				result = result / 100000000;
				result = result.toFixed(2) + "亿";
			   }else if(Math.abs(result) > 10000){
			    result = result/10000;
				result = result.toFixed(0) + "万";
			   }
               return result;  
			};	
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function cDayFunc(dp) { 
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			
			function BookingRmk(date){         				
				tt1 = date;
				var date1 = new Date(tt1);
				var date2 = new Date(dt);
				if(date1 < date2){
					k = 1;					
				}else{
					k = 0;
					tt1 = dt;
				}								
				a = 0;  //切换日期，清零
				getSource();				
			}
			
			function prev(){  //前一天
				pn = -1;
				var day = new Date(tt1);	
				day.setTime(day.getTime() - 24*60*60*1000);	
				tt1 = day.Format("yyyy-MM-dd");				
				BookingRmk(tt1);
			}
			
			function next(){  //后一天 				
				pn = 1;
				var day = new Date(tt1);	
				day.setTime(day.getTime() + 24*60*60*1000);	
				tt1 = day.Format("yyyy-MM-dd");				
				BookingRmk(tt1);							
			}
			
			var rqs = ""; //判断交易日用(缓存)
			var a = 0; 
			var b = 0;
			function getSource() {
				var div = document.getElementById("title");
				var qh = "<a style='position:absolute; left:350px;' href='javascript:void(0)' onclick='clearstorage()'>" + "清除缓存" + "</a>";				
				div.innerHTML = '<font color=#FF8C00; size="3">精选板块轮动<font size="1">&nbsp;&nbsp;&nbsp;&nbsp;' + qh + '</font></font><input style="width: 90px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';		
				var back = '<a href="javascript:prev();"  style="padding-left:10px;font-size:16px;color:#fff;">←</a>';				
				var forward = '<a href="javascript:next();"  style="font-size:16px;color:#fff;">→</a>';
				div.innerHTML += back + forward ;
				
				var url1 = "http://127.0.0.1:8880/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w21&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7";
				if(k == 0){				
					$.ajax({
						type: "get",
						url: url1,
						dataType: "json",
						async : false,
						cache:false,
						timeout:3000,					
						success: function(data) {					
							//alert(JSON.stringify(data))						
							//document.write(JSON.stringify(data));															
							tt1 = data.Day;							
							dt = tt1;
							day = new Date(tt1);
							rqs = tt1 + ";";  //判断交易日用										
						}
					});						
				}else{
					day = new Date(tt1);
					day.setTime(day.getTime());				
					for (i = 1; i < 100; i++){
						if(i > 1){
							day.setTime(day.getTime() + pn*24*60*60*1000);							
						}
						tt1 = day.Format("yyyy-MM-dd");						
						if(tt1 == dt){	
							k = 0;								
							getSource();
							break;
						}
						var urlt = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&Date=" + tt1; 					
						var res1 = [];
						$.ajax({
							type: "get",
							url: urlt,
							dataType: "text",
							async : false,
							cache:false,
							timeout:3000,						
							success: function(data) {							
								if(data.indexOf("MYSQL数据库链接出错!") == -1 && data.indexOf('"list":[]') == -1 && data.indexOf('"errcode":1020') == -1){
									var arr = JSON.parse(data);
									res1 = arr.list;								
								}else{
									res1.push("");
								}														
							}
						});
						if(res1[0].length != 0){							
							break;
						}
					}
				}
				
				var url2 = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&Date=" + tt1; 			
				var url = url1;
				if(k == "1"){
					url = url2;
				}
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {					
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));															
						for (i = 0; i < data.list.length; i++){
							res.push({"code":data.list[i][0],"name":data.list[i][1],"qd":data.list[i][2],"zf":data.list[i][3]});							
						}											
					}
				});	
				
				var div1 = document.getElementById('towrite1');																				
				div1.innerHTML = "<span style='color:#FFFF00'>" + tt1 + "</span>";					
				document.getElementById("PriceDate").value = tt1;	
				
				if(res.length != 0){
					Ctable(tt1,JSON.stringify(res),"towrite1");					
				}
				
				thcolor = $("th").css("color");				
				tdcolor = $("td a:first").css("color");		
								
				if(k == 0){					
					if(dt == tt1 && b == 0){ //竞价后切换
						a = 0;
						b++;
					}
					a++;
					//alert(a)
					if(a == 1){  //刷新或竞价后执行一次							
						gethis(); //交易日推算
					}else{					
						rdbj();
					}
				}else{
					gethis();						
				}						
			}
			
			var datahis = "";
			function gethis() {			
				if(localStorage.getItem('bkldrq') != null) {  //判断有无缓存日期
					var t = localStorage.getItem('bkldrq'); //取缓存日期
					if(t.split(";")[0] != tt1){  //如果缓存首日不等于最后交易日，重新计算					
						for (j = 1; j < x; j++){															
							gethisdata();
							var div = document.getElementById("towrite" + (j + 1));	
							div.innerHTML = "<span style='color:#FFFF00'>" + tt + "</span>";	
							Ctable(tt,datahis,"towrite" + (j + 1));							
						}
						if(k == 0){					
							localStorage.setItem('bkldrq', rqs);  //交易日期写入缓存
						}
					}else{  //否则取缓存数据
						for (i = 1; i < x; i++){
							var div = document.getElementById("towrite" + (i + 1));
							tt = t.split(";")[i];
							div.innerHTML = "<span style='color:#FFFF00'>" + tt + "</span>";
							datahis = localStorage.getItem('bkld' + tt);
							Ctable(tt,datahis,"towrite" + (i + 1));								
						}				
					}				
				}else{   //首次
					for (j = 1; j < x; j++){										
						gethisdata();
						var div = document.getElementById("towrite" + (j + 1));	
						div.innerHTML = "<span style='color:#FFFF00'>" + tt + "</span>";	
						Ctable(tt,datahis,"towrite" + (j + 1));						
					}							
					localStorage.setItem('bkldrq', rqs);  //交易日期写入缓存					
				}				
				rdbj();	
			}
									
			function gethisdata() {				
				day.setTime(day.getTime());				
				for (i = 1; i < 100; i++){	//节假日																										
					day.setTime(day.getTime() - 24*60*60*1000);
					tt = day.Format("yyyy-MM-dd");
					//alert(tt);
					var url = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&Date=" + tt; 										
					var res = [];
					$.ajax({
						type: "get",
						url: url,
						dataType: "text",
						async : false,
						cache:false,
						timeout:3000,						
						success: function(data) {							
							if(data.indexOf("MYSQL数据库链接出错!") == -1 && data.indexOf('"list":[]') == -1 && data.indexOf('"errcode":1020') == -1){
								var arr = JSON.parse(data);
								for (i = 0; i < arr.list.length; i++){
									res.push({"code":arr.list[i][0],"name":arr.list[i][1],"qd":arr.list[i][2],"zf":keepTwoDecimal(arr.list[i][3])});							
								}								
							}else{
								res.push("");
							}														
						}
					});
					if(res[0].length != 0){	
						rqs += tt + ";"
						if(localStorage.getItem('bkld' + tt) != null) {   //判断有无缓存数据														
							datahis = localStorage.getItem('bkld' + tt);    //取缓存数据							
						}else{														
							datahis = JSON.stringify(res);
							localStorage.setItem('bkld' + tt, datahis);  //历史单日数据写入缓存
						}				
						break;
					}
				}				
			}
			
			function rdbj() {		//高亮标记	
				//alert(1)
				var dms = "";
				var tlist = document.getElementById("towrites").getElementsByTagName("tr");
				for(var i = 1; i < tlist.length; i++){
					if(tlist[i].id != ""){
						dms += tlist[i].id.split('towrite')[0] + ",";
					}
				}
				
				<!-- 全部标记 -->
				<!-- for(var i = 1; i < tlist.length; i++){ -->
					<!-- var dm = tlist[i].id.split('towrite')[0]; -->
					<!-- if(dms.indexOf(dm) > -1 && dm != ""){ -->
						<!-- var ss = dms.split(dm);	 -->
						<!-- if(ss.length - 1 >= 5){																									 -->
							<!-- tlist[i].style.border = "2px solid #FF0000";							 -->
							<!-- //tlist[i].getElementsByTagName("a")[1].style.color = "#FF0000"; -->
						<!-- }else if(ss.length - 1 == 4){							 -->
							<!-- tlist[i].style.border = "2px solid #FF00FF"; -->
							<!-- //tlist[i].getElementsByTagName("a")[1].style.color = "#FF00FF"; -->
						<!-- } -->
					<!-- }					 -->
				<!-- } -->
				
				<!-- 以当日数据为基准标注 -->
				var div1 = document.getElementById('towrite1');
				var rows1 = div1.getElementsByTagName('tr');
				for(var i = 1; i < rows1.length; i++){
					var dm = rows1[i].id.split('towrite')[0];					
					var ss = dms.split(dm);					
					if(ss.length - 1 > 1){
						var rows = document.getElementById("towrites").getElementsByTagName('tr');
						for(var j = 0; j < rows.length; j++){
							var dmh = rows[j].id.split('towrite')[0];
							if(dmh == dm){								
								if(ss.length - 1 >= 5){																										
									rows[j].style.border = "2px solid #FF0000";
								}else if(ss.length - 1 == 4){									
									rows[j].style.border = "2px solid #FF00FF";
								}								
							}
						}
					}					
				}
			}
			
			
			
			function Ctable(tt,ss,id){
			//alert(ss)
				var json = JSON.parse(ss);				
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var n = 0;
				var b = 0;
				var h = 1;
				var gl = "强度";  //高亮				
				for(var key in json[0]){  //表头
					key = key.replace('code','代码').replace('name','名称').replace('zf','涨幅%').replace('qd','强度');
					//key = key.replace('ZJJE','主力净额').replace('gang','主力').replace('plate','板块').replace('index','异动次数');					
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);
					if(gl == key.replace("%","")){
							n = m;
							th.style.color = "#FF6633";	
						}					
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;
					var dm = "";
					var mc = "";
					for(var key in json[i]){ //行元素遍历						
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = dm + id;
						}else if(p == 2){  //名称列
							mc = rc;								
						}	
						td.innerHTML = "<a href='javascript:void(0)' style='float:left;'  onclick='showInform(\"" + tt + "#" + dm + "#" + mc + "#" + id + "\");changeCss(this,\"" + dm + id + "\",\"" + id + "\")'>" + rc + "</a>";
						
						if(p == n + 1){							
							td.getElementsByTagName("a")[0].style.color = "#FF6633";
						}																				
						tr.appendChild(td);							
						p++;
					}														
					if(mc.indexOf("ST") == -1 && h < 11){		//过滤ST	限制10行															
						tbody.appendChild(tr);
						h++;
					}	
				}
				var div = document.getElementById(id);					
				div.appendChild(table);
				table.id = id;
				changeTable(table,"0");		//隐藏某列	
				hover();				
			}
			
			//隐藏某列				
            function changeTable(table,ss) {	
				var trs = table.rows;
				ss = ss + '#';
				var aa = ss.split('#');
				for (var j = 0; j < aa.length; j++) {
					if(aa[j] != ""){
						for (var i = 0, len = trs.length; i < len; i++) {					
							var p = aa[j];
							var cell = trs[i].cells[p]; 
							cell.style.display = 'none';
						}
					}
				}					
			}
			
			//方式1		
			var pid = "";
			function changeCss1(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor; 					
				}	
				
				//5组选中行id集合
				if(pid.indexOf(id) > -1){				
					var aa = "";				
					var ss = pid.split(";");
					for(i = 0; i < ss.length-1; i++){
						if(ss[i].indexOf(id) > -1){						
							aa += hid + ";";
						}else{
							aa += ss[i] + ";";
						}				
					}
					pid = aa;
				}else{
					pid += hid + ";";
				}
				
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			//方式2：相同行高亮
			function changeCss(obj,hid,id){						
				var tlist = document.getElementById("towriter").getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor; 					
				}	
								
				pid = "";				
				var dm = hid.split("towrite")[0];				
				for(var i = 0; i < tlist.length; i++){
					var a = tlist[i].id;					
					if(tlist[i].id.split("towrite")[0] == dm){
						tlist[i].style.backgroundColor = "#483D8B";
						pid += tlist[i].id + ";";
					}					
				}					
			}
			
			
			function hover(){  //鼠标经过			
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头							
							if(pid.indexOf(this.id) == -1){  //过滤选中行
								this.style.background = bkcolor;
							}else{
								this.style.background = "#483D8B";
							}
						}						
					}					
				}
			}
			
						
			var rqb = "";
			var ztgp = "";
			var sx = 0;	
			var vlf = 0;
			function showInform(ss){
				ztgp = ss;
							
				var dms = ss.split('#');
				var rq = dms[0];				
				if(rq == ""){
					rq = tt1;
				}
				var dm = dms[1];
				var bk = dms[2];
				var id = dms[3];
				var div = document.getElementById('box');
				div.style.display = 'block';
				div.style.fontSize = "12px";
				
				//滚动条坐标
				var scLeft = 0;
				if($.browser.webkit){
					scLeft = $("#towriter").scrollLeft() + 200;
				}else{
					scLeft = scLeft + 200;
				}
				
				if(vlf != scLeft){
					vlf = scLeft;				
					div.style.left = scLeft + "px";
				}
				
				var div1 = document.getElementById('bar');							
				var gb = '<a href="javascript:close();"  style="float:right; color:#fff">关闭</a>';			
				div1.innerHTML = "<b style='color:#FFFF00;margin:5px;'>" + rq + "&nbsp;&nbsp;" + bk + gb +"</b>";
				
				update(rq,dm);	
				rqb = rq;
				
				if(rq == dt){
					sx = 1;
				}else{
					sx = 0;
				}				
			}
			
			
			function close() { 
				var div = document.getElementById("box");						
				div.style.display = "none";
				sx = 0;
			}
			
			var Order = 1;
			var old = 1; 
			var dmb = "";
			var type = "6";
			function update(tt,dm) {				
				dmb = dm;	
				var url = "";
				if(k == 0 && tt == tt1){
					url = "http://127.0.0.1:8880/w1/api/index.php?Order=" + Order + "&st=60&a=ZhiShuStockList_W8&c=ZhiShuRanking&PhoneOSNew=1&old=" + old + "&apiv=w21&Type=" + type + "&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + dm; 												
				}else{
					url = "http://127.0.0.1:8881/w1/api/index.php?st=60&Index=0&old=" + old + "&Order=" + Order + "&a=ZhiShuStockList_W8&apiv=w26&Type=" + type + "&c=ZhiShuRanking&PhoneOSNew=1&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + dm + "&Date=" + tt;												
				}
				
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {					
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));															
						for (i = 0; i < data.list.length; i++){
							res.push({"code":data.list[i][0],"name":data.list[i][1],"zf":data.list[i][6],"je":NumberTransform(data.list[i][13]),"lz":data.list[i][24],"zl":data.list[i][2],"lb":data.list[i][23],"zt":data.list[i][39]});							
						}											
					}
				});					
			
				//var json = JSON.parse(data);
				var json = res;
				
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var v = 0;				
				var gl = "领涨";  //高亮
				if(rs == 2){
					gl = "涨幅";
				}
				if(rs == 3){
					gl = "净额";
				}
				
				for(var key in json[0]){  //表头													
					key = key.replace('code','代码').replace('name','名称').replace('zf','涨幅%').replace('zl','主力').replace('lz','领涨');
					key = key.replace('lb','连板').replace('zt','主题').replace('zs','涨速%').replace('je','净额');
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);					
					if(key == "领涨" || key == "主力" || key == "连板" || key == "主题"){
						th.id = "BJ";
						th.style.color = "#FFA500";	
					}		
					if(gl == key.replace("%","")){
						v = m;
						th.style.color = "#FF6633";
						if((rs == 2 || rs == 3) && Order == 0){
							th.style.color = "#ADFF2F";								
						}
					}
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;	
					var dm = "";
					var mc = "";					
					for(var key in json[i]){ //行元素遍历					
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = dm;
						}					
						td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeTCss(this,\"" + dm + "\",\"gg\")'>" + rc + "</a>";
						
						if(p > 4){
							td.getElementsByTagName("a")[0].id = "BJ" + p;
							td.getElementsByTagName("a")[0].style.color = "#FFA500";													
						}
						if(p == v + 1){							
							td.getElementsByTagName("a")[0].style.color = "#FF6633";
							if((rs == 2 || rs == 3) && Order == 0){
								td.getElementsByTagName("a")[0].style.color = "#ADFF2F";
							}
						}						
						tr.appendChild(td);
						p++;
					}						
					tbody.appendChild(tr);
				}	
				//var div = document.getElementById("inform");
				var div = document.getElementById("content");								
				div.scrollTop = 0; //回到顶部	
				div.innerHTML = "";					
				div.appendChild(table);
				table.id = "gg";					
				
				//var table=div.getElementsByTagName("table")[0];
				makeSortable(table);			
				ihover();
			}
			
			var trid = "";
			function changeTCss(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = cbkcolor; 					
				}
				trid = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function ihover(){  //鼠标经过
				var rows = document.getElementById("gg").getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid){  //过滤选中行
								this.style.background = cbkcolor;
							}else{
								this.style.background = "#483D8B";
							}
						}						
					}					
				}
			}	
			
			var pt = 0;
			var rs = 0
			function makeSortable(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
							//alert(n);	
							
							if(n == 2 || n == 3){
								rs = n;
								Order = (pt%2 == 0) ? "1" : "0";								
								old = 0; 
								if(n == 2){
									type = "6"
								}else{
									type = "1";
								}
								update(rqb,dmb);
								pt++;
							}
							
							if(old == 0 && n != 2 && n != 3){							
								rs = 0;
								Order = 1;
								old = 1; 								
								update(rqb,dmb);
							}
							if(n < 2 || n > 3){
								showCol(n);		//高亮
							}
							var tbody=table.tBodies[0];
							var rows=tbody.getElementsByTagName("tr");
							rows=Array.prototype.slice.call(rows,0);

							//基于第n个<td>元素的值对行排序
							rows.sort(function(row1,row2){
								headtxt = headers[n].textContent;								
								var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
								var cell2=row2.getElementsByTagName("td")[n];																
								var val1=cell1.textContent||cell1.innerText;//获得文本内容
								var val2=cell2.textContent||cell2.innerText;
								if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("主力") != -1|| headtxt.indexOf("主题") != -1){
									val1 = val1;
									val2 = val2;
								}else if(headtxt.indexOf("连板") != -1){								
									val1 = val1.replace("昨日首板","-1").replace("首板","1").replace("连板","");
									if(val1.indexOf("天")>-1){
										val1 = val1.split("天")[0];
									}else if(val1.indexOf("昨")>-1){
										val1 = 0;
									}else if(val1 == ""){
										val1 = -2;
									}										
									val1 = parseFloat(val1);
								
									val2 = val2.replace("昨日首板","-1").replace("首板","1").replace("连板","");
									if(val2.indexOf("天")>-1){
										val2 = val2.split("天")[0];
									}else if(val2.indexOf("昨")>-1){
										val2 = 0;
									}else if(val2 == ""){
										val2 = -2;
									}									
									val2 = parseFloat(val2);
								}else if(headtxt.indexOf("领涨") != -1){
									val1 = val1.replace("龙十","龙一十").replace("破板","1000");
									val2 = val2.replace("龙十","龙一十").replace("破板","1000");
									if(val1 == ''){
										val1 = '1001';
									}
									if(val2 == ''){
										val2 = '1001';
									}
									if(val1.indexOf("龙") != -1){
										val1 = ChineseToNumber(val1.replace("龙",""));										
									}										
									if(val2.indexOf("龙") != -1){
										val2 = ChineseToNumber(val2.replace("龙",""));
										
									}
									//val2 = parseFloat(val2);									
								}else{
									if(val1 == "-"){
										val1 = " ";
									}
									if(val2 == "-"){
										val2 = " ";
									}
									val1 = val1.replace(" ","0").replace("无","1000").replace("NaN","0");
									val2 = val2.replace(" ","0").replace("无","1000").replace("NaN","0");
									if(val1.indexOf("万") != -1){
										val1 = parseFloat(val1)*10000;
									}else if(val1.indexOf("亿") != -1){
										val1 = parseFloat(val1)*100000000;
									}else{
										val1 = parseFloat(val1);
									}
									
									if(val2.indexOf("万") != -1){
										val2 = parseFloat(val2)*10000;
									}else if(val2.indexOf("亿") != -1){
										val2 = parseFloat(val2)*100000000;
									}else{
										val2 = parseFloat(val2);
									}
								}
								if(val1<val2){
									return -1;
								}else if(val1>val2){
									return 1;
								}else{
									return 0;
								}
								
							});
							if(flag){
								rows.reverse();								
							}
							
							for(var i=0;i<rows.length;i++){
								tbody.appendChild(rows[i]);
							}

							flag=!flag;							
						}
					}(i));
				}
			}
			
			function showCol(iCol){			
				var oTable = document.getElementById("content").getElementsByTagName('table')[0];
				for (i=0;i < oTable.rows.length; i++){										
					for (j=0;j < oTable.rows[0].cells.length; j++){
						oTable.rows[i].cells[j].style.color = "#E5E5E5";
						
						if(oTable.rows[i].cells[j].id == "BJ"){
							oTable.rows[i].cells[j].style.color = "#FFA500"; 
						}						
					}
					oTable.rows[i].cells[iCol].style.color = "#FF6633";					
				}

				otagsA = oTable.getElementsByTagName("a");  //a变色
				for (i = 0; i < otagsA.length; i++) {
					otagsA[i].style.color = "#E5E5E5";
					if(otagsA[i].id.indexOf("BJ") > -1){
						otagsA[i].style.color = "#FFA500";								
					}
					if(otagsA[i].id.replace("BJ","") == iCol + 1){
						otagsA[i].style.color = "#FF6633";
					}
				}								
			}
			
			var chnNumChar = {零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9};

			var chnNameValue = {
			  十:{value:10, secUnit:false},
			  百:{value:100, secUnit:false},
			  千:{value:1000, secUnit:false},
			  万:{value:10000, secUnit:true},
			  亿:{value:100000000, secUnit:true}
			}

			function ChineseToNumber(chnStr){
			  var rtn = 0;
			  var section = 0;
			  var number = 0;
			  var secUnit = false;
			  var str = chnStr.split('');

			  for(var i = 0; i < str.length; i++){
				var num = chnNumChar[str[i]];
				if(typeof num !== 'undefined'){
				  number = num;
				  if(i === str.length - 1){
					section += number;
				  }
				}else{
				  var unit = chnNameValue[str[i]].value;
				  secUnit = chnNameValue[str[i]].secUnit;
				  if(secUnit){
					section = (section + number) * unit;
					rtn += section;
					section = 0;
				  }else{
					section += (number * unit);
				  }
				  number = 0;
				}
			  }
			  return rtn + section;
			}
			
			function clearstorage(){				
				if(localStorage.getItem('bkldrq') != null){						
					localStorage.removeItem('bkldrq'); //清除缓存localStorage
				}
				
				var day = new Date();
				day.setTime(day.getTime());			
				for (i = 1; i < 300; i++){																		
					day.setTime(day.getTime() - 24*60*60*1000);
					var ts = day.Format("yyyy-MM-dd");
					
					if(localStorage.getItem('bkld' + ts) != null){	
					
						localStorage.removeItem('bkld' + ts); //清除缓存localStorage
					}
				}
				alert('清除完成');
			}
		</script>
		
		<script>
		var dragBox = function (drag, wrap) {

			function getCss(ele, prop) {
				return parseInt(window.getComputedStyle(ele)[prop]);
			}

			var initX,
			initY,
			dragable = false,
			//wrapLeft = getCss(wrap, "left"),
			wrapTop = getCss(wrap, "top");
			
			drag.addEventListener("mousedown", function (e) {
				wrapLeft = getCss(wrap, "left"),  //获取box启动后坐标
				
				dragable = true;
				initX = e.clientX;
				initY = e.clientY;
			}, false); 

			document.addEventListener("mousemove", function (e) {		
				if (dragable === true ) {
					var nowX = e.clientX,
					nowY = e.clientY,
					disX = nowX - initX,
					disY = nowY - initY;
					wrap.style.left = wrapLeft + disX + "px";
					wrap.style.top = wrapTop + disY + "px";
				}
			});

			drag.addEventListener("mouseup", function (e) {
				dragable = false;
				wrapLeft = getCss(wrap, "left");
				wrapTop = getCss(wrap, "top");
				}, false); 
		};

		dragBox(document.querySelector("#bar"), document.querySelector("#box"));
    </script>
	
	
	</body>
</html>